(ns com.jeff.tracer.tracer-test)

(use 'com.jeff.tracer.tracer)

(def same-points-have-zero-distance
  (fn []
    (let [p (list 0 0 0)]
      (assert (= (distance p p) 0)))))

(def test-distance-unique-points
  (fn []
    (let [p1 (list 0 0 0)
          p2 (list 1 1 1)
          expected (Math/sqrt 3)]
      (assert (= (distance p1 p2) expected)))))

(def test-closest-points
  (fn []
    (let [p1 (list 0 0 0)
          p2 (list 0 1 0)
          p3 (list 2 2 2)]
      (assert (= (closest p1 (list p2 p3)) p2)))))

(def test-make-point
  (fn []
    (let [ray {:origin (list 0 0 0) :dir (list 0 0 1)}
          t 1
          expected (list 0 0 1)]
      (assert (= (make-point ray t) expected)))))

(def test-sphere-intersection
  (fn []
    (let [ray {:origin (list 0 0 -3) :dir (list 0 0 1)}
          sphere {:is-a 'SPHERE :center (list 0 0 1) :radius 1}
          expected (list 0 0 0)]
      (assert (= (intersect ray sphere) expected)))))

;=======================================

(same-points-have-zero-distance)
(test-distance-unique-points)
(test-closest-points)
(test-make-point)
(test-sphere-intersection)